Skip to content

csdb: sync the BerkeleyDB log before a checkpoint is saved - #47

Merged
EnzinoBB merged 1 commit into
masterfrom
fix/berkeleydb-flush-before-checkpoint
Oct 17, 2026
Merged

EnzinoBB merged 1 commit into
masterfrom
fix/berkeleydb-flush-before-checkpoint

Conversation

@EnzinoBB

Copy link
Copy Markdown
Collaborator

BlockChain flushes the block storage before it saves a checkpoint, so that the checkpoint never gets ahead of the blocks on disk. The BerkeleyDB backend had no flush() (the base class returns true): its commits run with DB_TXN_NOSYNC, so their log records can stay in the in-process log buffer.

Found by the new all-storage-power-cut scenario (every node killed at once): the BerkeleyDB pruned node had checkpoint qs/2506 but only blocks up to 2504 in the database, and its next start failed with startSequence > last_seq_in_db + 1 and stopped the node for good.

flush() now calls DbEnv::log_flush(nullptr), which writes and syncs the log, once per checkpoint (about once a minute). With the fix, all-storage-power-cut and all-storage-crash pass (run 39018183898). No block or consensus change.

🤖 Generated with Claude Code

BlockChain flushes the block storage before it saves a checkpoint, so
that the checkpoint never gets ahead of the blocks on disk. The
BerkeleyDB backend had no flush(): its commits run with DB_TXN_NOSYNC,
so their log records can stay in the in-process log buffer. When the
process was killed, the checkpoint survived but the last blocks did not,
and the next start failed with "startSequence > last_seq_in_db + 1" and
stopped the node.

flush() now writes and syncs the log, once per checkpoint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@EnzinoBB EnzinoBB added the testnet Run the private 7-node network workflow on this PR label Oct 17, 2026
@EnzinoBB
EnzinoBB merged commit 2d83814 into master Oct 17, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testnet Run the private 7-node network workflow on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant